import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;

public class StoneWall {
    private int x;
    private int health = 3;
    private boolean active = true;

    private Image stoneImage;
    private Image stoneBrokenImage;
    private Image stoneBroken2Image;

    public StoneWall(int x, Image stone, Image stoneBroken, Image stoneBroken2) {
        this.x = x;
        this.stoneImage = stone;
        this.stoneBrokenImage = stoneBroken;
        this.stoneBroken2Image = stoneBroken2;
    }

    public void update(int speed) {
        x -= speed;
    }

    public void render(GraphicsContext gc, int screenHeight, int gridSize) {
        if (active) {
            double wallY = screenHeight - gridSize * 2.2;
            Image img = stoneImage;
            if (health == 2) img = stoneBrokenImage;
            else if (health == 1) img = stoneBroken2Image;

            gc.drawImage(img, x, wallY, gridSize*1.2, gridSize*1.65);
        }
    }

    public boolean checkCollision(int playerX, int playerY, int width, int height, int gridSize) {
        if (active) {
            double wallY = GameConstants.getScreenHeight() - gridSize * 2;
            return playerX + width > x +0.3*gridSize&&
                    playerX < x + gridSize &&
                    playerY + height > wallY;
        }
        return false;
    }

    public boolean checkBombCollision(Bomb bomb, int gridSize) {
        if (active) {
            double wallY = GameConstants.getScreenHeight() - gridSize * 2;
            double wallHeight = gridSize * 1.5;

            if (bomb.x + bomb.width > x &&
                    bomb.x < x + gridSize &&
                    bomb.y + bomb.height > wallY &&
                    bomb.y < wallY + wallHeight) {

                health--;
                if (health <= 0) {
                    active = false;
                }
                return true;
            }
        }
        return false;
    }

    public int getX() {
        return x;
    }
}